package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.mapper.entity.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface TaskManageMapper extends BaseMapper<Task> {
    @Delete("<script>" +
            "DELETE FROM task" +
            " WHERE task_id IN" +
            " <foreach collection='list' index='index' open='(' separator=',' close=')' item='taskList' >" +
            "   #{taskList.taskId}" +
            " </foreach>" +
            "</script>")
    void batchDeleteTask(List<Task> taskList);

    @Select("SELECT COUNT(DISTINCT id) FROM student")
    int getTotalStudent();
    @Select("SELECT * FROM student")
    List<Student> selectStudentList();
    @Insert("INSERT INTO `task` (task_type, task_name, task_sequence, is_main_quest, points_awarded, attributes_awarded, " +
            "badge_awarded, start_time, end_time, last_update, task_status, task_label,task_location,latitude,longitude," +
            "is_navigable,is_location,checkin_description,total_questions,passing_score,exam_duration,coupons_awarded,bank_id) " +
            "VALUES (#{taskType}, #{taskName}, #{taskSequence}, #{isMainQuest}, #{pointsAwarded}, #{attributesAwarded}, " +
            "#{badgeAwarded}, #{startTime}, #{endTime}, #{lastUpdate}, #{taskStatus}, #{taskLabel}, #{taskLocation}, #{latitude}, #{longitude}," +
            "#{isNavigable}, #{isLocation}, #{checkinDescription}, #{totalQuestions}, #{passingScore}, #{examDuration}, #{couponsAwarded},#{bankId}) ")
    @Options(useGeneratedKeys = true, keyProperty = "taskId", keyColumn = "task_id")
    Task addTask(Task newRequest);
    @Select("SELECT * FROM student WHERE college_id = #{selectedCollege} ")
    List<Student> selectStudentByCollege(int selectedCollege);
    @Select("SELECT * FROM student WHERE major_id = #{selectedMajor} ")
    List<Student> selectStudentByMajor(int selectedMajor);
    @Select("SELECT * FROM student WHERE clazz = #{selectedClazz} ")
    List<Student> selectStudentByClazz(int selectedClazz);
    @Select("SELECT * FROM student WHERE number = #{studentNumber} ")
    List<Student> selectStudentByNumber(String studentNumber);

    @Insert("<script>" +
            "INSERT INTO student_task (student_id, task_id, task_allocation)" +
            " VALUES" +
            " <foreach collection='list' item='newStudentTask' separator=','>" +
            " (#{newStudentTask.studentId}, #{newStudentTask.taskId}, #{newStudentTask.taskAllocation})" +
            " </foreach>" +
            "</script>")
    int batchInsertStudentTask(List<StudentTask> newStudentTask);

    @Select("SELECT COUNT(*) FROM question WHERE bank_id = #{bankId};")
    int getTotalQuestions(int bankId);
    @Select("SELECT COUNT(*) FROM student WHERE college_id = #{collegeId};")
    int getTotalCollegeStudent(int collegeId);
    @Select("SELECT COUNT(*) FROM student WHERE major_id = #{majorId};")
    int getTotalMajorStudent(int majorId);
    @Select("SELECT COUNT(*) FROM student WHERE clazz = #{clazz};")
    int getTotalClassStudent(int clazz);
    @Select("SELECT COUNT(*) FROM student WHERE number = #{studentNumber};")
    int getStudent(String studentNumber);
}
